#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int prostoe(int n)
{   
    for (int d = 2; d < sqrt(n) + 1; d++)
        if (n % d == 0)
            return false;
    return true;
}


int main()
{
    string st;
    getline (cin, st);
    
    int j = st.length();
    int spaces = 0;
    for (int i = 0; i < j; ++i)
        if (st[i] == ' ')
            spaces++;
    
    if (spaces != 2) 
        cout << "Wrong input"; 
    else {
        string word = ""; 
        string word1 = "";
        string word2 = "";
        string word3 = "";
        for (int i = 0; i < j; ++i)
            if (st[i] != ' ')
                word = word + st[i];
            else {
                if (word1.length() == 0)
                    word1 = word;
                else
                    if (word2.length() == 0)
                        word2 = word;
                word = "";
                }
        word3 = word;
        
        string arr[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        
        int a1 = -1, a2 = -1, a3 = -1;
        
        for (int i=0; i < 10; i++) {
            if (word1 == arr[i])
                a1 = i; 
            if (word2 == arr[i])
                a2 = i; 
            if (word3 == arr[i])
            a3 = i;
        }
        
        if (a1 == 0 or a1 == -1 or a2 == -1 or a3 == -1)
            cout << "Wrong input";
        else {
            int x = a1 * 100 + a2 * 10 + a3;
            int num1, num2;
            num1 = x + 1;
            num2 = x - 1;
            
            bool fl = true;
            
            while (fl) {
                num1 = num1 - 1;
                num2 = num2 + 1;
                if (prostoe(num1)) {cout << num1; fl = false;}
                else
                    if (prostoe(num2)) {cout << num1; fl = false;}
            }
        }
    }
}